package exer;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author tongchen
 * @create 2023-02-08 15:19
 */
public class TestAtomic {
    public static void main(String[] args) throws InterruptedException {
        AtomicInteger atomicInteger = new AtomicInteger();
         Thread t1 =new Thread(()->{
                    for (int i=0;i<50000  ;++i){
                        atomicInteger.getAndIncrement();
                    }
                 });
         t1.start();
          Thread t2 =new Thread(()->{
              for (int i = 0; i < 50000; i++) {
                  atomicInteger.getAndIncrement();
                  atomicInteger.incrementAndGet();
                  atomicInteger.getAndDecrement();
                  atomicInteger.decrementAndGet();
              }
                  });
          t2.start();
          t1.join();
          t2.join();
        System.out.println(atomicInteger);
    }
}
